/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.generalisator;

import java.util.Random;

/**
 *
 * @author Thomas
 */
public class GenEducation implements Generalisator{
    private String[] university = {"Bachelors", "Masters", "Doctorate"};
    private String[] pro = {"Prof-school", "Assoc-acdm", "Assoc-voc", "Some-college"};
    private String[] elementary = {"Preschool", "1st-4th"};
    private String[] midleschool = {"5th-6th", "7th-8th", "9th"};
    private String[] highschool = {"10th", "11th", "12th", "HS-grad"};
    
    private String[] higher = {"University", "Pro"};
    private String[] lower = {"Elementary", "Midleschool", "Highschool"};
            
    @Override
    public String gen(String value) {
        for(String target : higher){
            if(value.contains(target))
                return "Higher";
        }
        for(String target : elementary){
            if(value.contains(target))
                return "Elementary";
        }
        for(String target : midleschool){
            if(value.contains(target))
                return "Midleschool";
        }
        for(String target : lower){
            if(value.contains(target))
                return "Lower";
        }
        for(String target : university){
            if(value.contains(target))
                return "University";
        }
        for(String target : pro){
            if(value.contains(target))
                return "Pro";
        }        
        
        for(String target : highschool){
            if(value.contains(target))
                return "Highschool";
        }
        return "*";
    }
    
    @Override
    public int getMaxGeneralisation() {
        return 4;
    }

    @Override
    public double getLength(String value) {
        if(value.equals("*"))
            return 4.0;
        for(String target : higher){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : elementary){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : midleschool){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : lower){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : university){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : pro){
            if(value.contains(target))
                return 1.0;
        }        
        
        for(String target : highschool){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : lower){
            if(value.contains(target))
                return 3.0;
        }
        for(String target : higher){
            if(value.contains(target))
                return 3.0;
        }
        return 2.0;
    }

    @Override
    public double getMaxLength() {
        return 4.0;
    }

    @Override
    public String getUngeneralisation(String value) {
        Random rand = new Random(System.nanoTime());
        if(value.equals("*"))
            return "Highschool";
        if(value.equals("Higher"))
            return higher[rand.nextInt(higher.length)];
        if(value.equals("Elementary"))
            return elementary[rand.nextInt(elementary.length)];
        if(value.equals("Midleschool"))
            return midleschool[rand.nextInt(midleschool.length)];
        if(value.equals("Lower"))
            return lower[rand.nextInt(lower.length)];
        if(value.equals("University"))
            return university[rand.nextInt(university.length)];
        if(value.equals("Pro"))
            return pro[rand.nextInt(pro.length)];
        if(value.equals("Highschool"))
            return highschool[rand.nextInt(highschool.length)];
        return highschool[rand.nextInt(highschool.length)];
    }

    @Override
    public int getGeneralisationLevel(String value) {
        if(value.equals("*"))
            return 3;
        for(String target : higher){
            if(value.contains(target))
                return 1;
        }
        for(String target : elementary){
            if(value.contains(target))
                return 1;
        }
        for(String target : midleschool){
            if(value.contains(target))
                return 1;
        }
        for(String target : lower){
            if(value.contains(target))
                return 1;
        }
        for(String target : university){
            if(value.contains(target))
                return 1;
        }
        for(String target : pro){
            if(value.contains(target))
                return 1;
        }        
        
        for(String target : highschool){
            if(value.contains(target))
                return 1;
        }
        for(String target : lower){
            if(value.contains(target))
                return 2;
        }
        for(String target : higher){
            if(value.contains(target))
                return 2;
        }
        return 1;
    }
    
}
